package com.mt.components.tab{
	import com.mt.components.utils.IconUtility;
	import com.mt.components.utils.ImageSource;
	
	import flexlib.containers.SuperTabNavigator;
	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.core.Container;
	import mx.core.FlexGlobals;
	
	/**      
	 * 类名称：TabFactory<br>   
	 * 类描述：<br>
	 * 创建人：MaTeng<br>
	 * 创建时间：Oct 6, 2012 9:10:49 AM<br>
	 * 修改人：MaTeng<br>
	 * 修改时间：Oct 6, 2012 9:10:49 AM<br>
	 */
	public class TabFactory{
		
		public static const NUM:int = 10;
		
		private static var instance:TabFactory;
		
		public var tab:SuperTabNavigator;
		
		public function TabFactory(){
			if(instance != null){
				throw new Error("please use singleton");
			}
		}
		
		public static function getInstance():TabFactory {
			if(instance == null){
				instance = new TabFactory();
			}
			return instance;
		}
		
		/**
		 * 增加tab页 
		 * @param dis
		 * @param lable
		 */		
		public function addTab(dis:Container , lable:String , icon:String=null):void{
			var arr:Array = tab.getChildren();
			if(arr.length >= NUM){
				Alert.show("您打开的页面过多，请先关闭不必的页面！");
				return;
			}
			for(var i:int=0;i<arr.length;i++){
				if(arr[i].label == lable){
					tab.selectedIndex = i;
					return;
				}
			}
			dis.label = lable;
			if(icon){
				dis.icon = IconUtility.getClass(dis , icon , 25 , 25);
			}
			dis.percentWidth = 100;
			dis.percentHeight = 100;
			tab.addChild(dis);
			tab.selectedIndex = tab.numChildren - 1;
		}
	}
}